package Package5;

import java.util.Random;

public class Role {
    private String name;
    private int blood;

    public Role() {
    }

    public Role(String name, int blood) {
        this.name = name;
        this.blood = blood;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBlood() {
        return blood;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    //role1 attack role2
    //role1.attack(role2)
    public void attack(Role role) {
        Random r = new Random();
        //伤害 1--30
        int hurt = r.nextInt(30) + 1;
        int remainBlood = role.blood - hurt;
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        role.setBlood(remainBlood);
        System.out.println(this.getName() + "举起拳头攻击了" + role.getName() + ",造成了" + hurt + "伤害。" + role.getName() + "还剩" + role.getBlood() + "点血。");
    }


}
